﻿Imports AutoMapper
Imports DomusDotNet.Sbm.Services

Namespace Wcf
    Public NotInheritable Class WcfMappingHelper
        Private Sub New()

        End Sub

        Public Shared Sub CreateMapping()
            Mapper.CreateMap(Of ServiceError, [Error])()

            Mapper.CreateMap(Of ObjectModel.Book, BookBase)() _
                .ForMember(function(a) a.Authors, Sub(x) x.MapFrom(Function(a)
                                                           Dim authors = From i In a.Authors
                                                                        Select String.Format("{0} {1}", i.Surname, i.Name)
                                                           Return authors
                                                       End Function)) _
				.ForMember(function(a) a.Editor, sub(x) x.Mapfrom(function(a) if(a.editor is nothing, "", a.editor.Nominative))) _
				.formember(function(a) a.BookStatus, sub(x) x.mapfrom(function(a) if(a.available, BookStatusEnum.Available,BookStatusEnum.OnLoan)))

        End Sub

    End Class
End Namespace
